<?php
/**
 * ENV
 *
 * @version 0.2a
 */

// No direct access
defined( "__DEENZO__" ) or die( "deenzo$" );  
 
function varz( &$o, $k = "", $v = "" ) {
    
    if ( strpos( $k, "." ) !== false ) {
        foreach( preg_split( "/\./", $k ) as $hash ) {
        
        /** Support for OBJECTS with same notation */
        eval( 'if ( !is_object( $o' . $index . ' ) )
                  $index .= ( $hash !== "" ) ? "[\'$hash\']" : "[]";
               else
                  $index .= "->$hash";' );     
        }   
        
        $k = $index;
		
    } else
        $k = ( $k ) ? "['$k']" : "";
    
    /* Key-array assignation */
    if ( $k and ( $v or  $v === 0 ) ) 
		eval( '$o'. $k . ' = $v;' );
	
	/* Return Key-value or UNSET ( if V is null ) */
    elseif ( $k ) { 
		
		if ( $v === null ) 
			eval( 'unset( $o' . $k . ');');
        else {
			eval( '$v = $o' . $k . ';');   
        
			return $v; 
		} 
   
    } else                     
		return $o;
}


function env( $k = "", $v = "" ) { 
	return varz( $_ENV, $k, $v ); 
}

function server( $k = "" ) {
    return varz( $_SERVER, $k );
}

/** Secure HTTP REQUEST method */
function http( &$o, $k = "", $v = "" ) {
    return varz( $o, $k, $v );
}

/* GET */
function get( $k = "", $v = "" ) {
    return http( $_GET, $k, $v );
}

/* POST */
function post( $k = "", $v = "" ) {
    return http( $_POST, $k, $v );
}
